<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <link href="${ctx}/css/style.css" type="text/css" rel="stylesheet" /> 
    <link href="${ctx}/js/ztree/css/demo.css" type="text/css" rel="stylesheet">
    <link href="${ctx}/js/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css" rel="stylesheet">
    <script src="${ctx}/js/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="${ctx}/js/jquery.cookie.js" type="text/javascript"></script>
    <script src="${ctx}/js/jquery.treeview.js" type="text/javascript"></script>
    <script type="text/javascript" src="${ctx}/js/ztree/js/jquery.ztree.core-3.3.min.js"></script>
    <script type="text/javascript" src="${ctx}/js/ztree/js/jquery.ztree.excheck-3.3.min.js"></script>
  
    <title>安全系统—角色列表</title>
<body>
  <div class="m_right">
    <div class="m_r_tips">
        <div class="m_r_lefttips">您现在的位置：<a href="${ctx}/admin/home.jsp">首页</a>&gt;用户权限管理&gt;查看角色权限</div>
        <jsp:include page="/commons/admin/admin_login_remind.jsp"/>
    </div>

    <s:if test="hasActionMessages()">
          <div class="success">
               <s:actionmessage/>
          </div>
    </s:if>
     <s:if test="hasActionErrors()">
          <div class="error">
               <s:actionerror/>
          </div>
    </s:if>
    <div style=”color:red”>
        <s:fielderror />
    </div>
    <div style="font-size: 14px;font-weight: bolder;padding: 10px 20px;">
        角色名：${role.roleName}
    </div>
    <div class="zTreeDemoBackground left fl">
        <ul id="permTree" class="ztree"></ul>
    </div>
    <div class="zTreeDemoBackground right fl">
        <ul class="ztree">
            <li><span>选择左边复选框，然后点击授权</span><br>
            <a href="#" class="m_r_bnt1" >
            <input type="button" value="授权" onclick="auth_permissions();"/>
            </a></li>
        </ul>
    </div>
    <!-- role id hidden -->
    <s:form action="addOrUpdateRolePerm" method="post" namespace="/admin/role" id="auth_form">
             <input type="hidden" name="rid" value="${rid}" id="rid" />
             <input type="hidden" name="origin_perm" value="" id="origin_perm" />
             <input type="hidden" name="change_perm" value="" id="change_perm" />
    </s:form>
</div>
</body>
  <SCRIPT type="text/javascript">
        <!--
        var setting = {
            check: {
                enable: true,
                //被勾选时：关联父，关联子
                //取消勾选时：关联子
                chkboxType: { "Y" : "ps", "N" : "s" }
            },  
      

            data: {
                 simpleData: {
                     enable: true
                 }
            },
            callback:{
                    //onClick:function(event, treeId, treeNode, clickFlag){ if(!treeNode.isParent) alert(treeId + " " +treeNode.value);},
                    //onCheck: function(event, treeId, treeNode){if(!treeNode.isParent)  alert(treeId + " " +treeNode.value  + " " + treeNode.pId);},
                    //beforeExpand: beforeExpand,
                    //onExpand: onExpand
             }
        };

       var treeData = '${menTree}';
       var zNodes = eval('('+treeData+')');

        $(document).ready(function(){
            $.fn.zTree.init($("#permTree"), setting,zNodes);
        });
        
        function auth_permissions() {
        	var origin_perm_values  = getOriginPermission();
        	$("#origin_perm").val(origin_perm_values);
        	var treeObj = $.fn.zTree.getZTreeObj("permTree");
            var nodes = treeObj.getCheckedNodes(true);
            if (nodes.length == 0) {
                if ($("#origin_perm").val() == ""){
                    alert("未选中任何权限");
                    return;
                } else {
                    if (!confirm('确定删除所有权限吗')) {
                        return;
                    }
                }
            }
            var change_perm_values= "";
        	for (var i=0; i<nodes.length; i++) {
        		change_perm_values = change_perm_values + nodes[i].value + "#";
            };
            
            $("#change_perm").val(change_perm_values);
            window.console && console.log("change_perm %o", change_perm_values);
            window.console && console.log("origin_perm_values %o", origin_perm_values);
            $("#auth_form").submit();
        }
        
        function getOriginPermission() {
        	var originPermValues = "";
        	for (var i=0; i<zNodes.length; i++) {
        		 if(zNodes[i].checked) {
        			 originPermValues = originPermValues + zNodes[i].value + "#";
        		 }       		
        	}
        	return originPermValues;
        }
        
        //-->
    </SCRIPT>
</html>
